package com.supermap.pisaclient.mine;

import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.supermap.pisaclient.R;
import com.supermap.util.view.ViewInject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


public class PersonInfoActivity extends AppCompatActivity {

    private ListView user_info;
    @ViewInject(R.id.user_headimage)
    private ImageView user_headimage;
    private SimpleAdapter adapter;
    String[] info_name = new String[]{"用户昵称", "用户名", "手机号码", "所在城市", "邮箱", "部门", "公司/企业"};
    String[] info_data = new String[]{"啦啦啦啦", "test219", "13912345678", "530112", "1234567@163.com", "气象事业部", "北京超图"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_personinfo);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }

        initview();
    }

    private void initview() {
        user_info = (ListView) findViewById(R.id.user_info);

        List<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>();

        for(int i = 0; i <info_name.length; i++){
            HashMap<String, Object> map1 = new HashMap<String, Object>();
            map1.put("info_name", info_name[i]);
            map1.put("info_data", info_data[i]);
            data.add(map1);
        }

        adapter = new SimpleAdapter(PersonInfoActivity.this, data, R.layout.user_personinfo_listitem,  new String[] { "info_name", "info_data"},  new int[] { R.id.info_name, R.id.info_data});

        user_info.setAdapter(adapter);

//        user_headimage.setOnClickListener(new View.OnClickListener() {
//            public void onClick(View view) {
//                AlertDialog.Builder dialog = new AlertDialog.Builder(PersonInfoActivity.this);
//                dialog.setPositiveButton("拍照", new DialogInterface.OnClickListener() {
//                            @Override
//                            public void onClick(DialogInterface dialog, int which) {
//                                imageName = File.separator + getStringToday() + ".jpg";
//
//                                // 调用系统的拍照功能
//                                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//                                String status = Environment.getExternalStorageState();
//                                if(status.equals(Environment.MEDIA_MOUNTED)){
//                                    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(
//                                            Environment.getExternalStorageDirectory(), imageName)));
//                                }else{
//                                    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(
//                                            PersonInfoActivity.getFilesDir(), imageName)));
//                                }
//                                activity.startActivityForResult(intent, PHOTOGRAPH);
//                            }
//                        });
//                dialog.setNegativeButton("本地相册", new DialogInterface.OnClickListener() {
//                            @Override
//                            public void onClick(DialogInterface dialog, int which) {
//
//                            }
//                        });
//            }
//        });
    }

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            this.finish();
        } else { }
        return false;
    }

//    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
////        if ((resultCode == RESULT_OK) && (requestCode == Constant.IMAGE_CAPTURE_REQUEST)) {
////            mPath = CommonImageUtil.getInstance(this).getPicturePath();
////            mBmp = CommonImageUtil.getInstance(this).decodeFile(mPath, 100, 100);
////            mIvHeader.setImageBitmap(CommonUtil.toRoundBitmap(mBmp));//显示本地的原图
////            mIsSelected = true;
////        } else
//            if ((resultCode == RESULT_OK) && (requestCode == Constant.IMAGE_GET_REQUEST)) {
//            Uri uri = data.getData();
//            String[] proj = {MediaStore.Images.Media.DATA};
//            Cursor cursor = getContentResolver().query(uri, proj, null, null, null);
//            if(cursor!=null) {
//                cursor.moveToFirst();
//                int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
//                mPath = cursor.getString(column_index);
//                cursor.close();
//            } else {
//                mPath = data.getData().getPath();
//            }
//            mBmp = CommonImageUtil.getInstance(this).decodeFile(mPath, 100, 100);
//            mIvHeader.setImageBitmap(CommonUtil.toRoundBitmap(mBmp));
//            mIsSelected = true;
//        }
//    }
}
